var userSessionName='userSessionChdWlgcFYB';
var dbTableHead ='chdwlgcsysDB_';

function getUserInfo() {
    var userJsonStr = sessionStorage.getItem(userSessionName);
    var userName='游客';
    var userEntitySession = JSON.parse(userJsonStr);
    var userAccount='';//用户唯一ID,这里是用账号作为唯一的id
    var enterAccount='';//企业唯一ID,这里是用账号作为唯一的id
    if (userEntitySession!=null){
        var transData= {
            userAccount:userEntitySession.userAccount,
            userSession:userEntitySession.csrftokenfyb,
        };
        userName=userEntitySession.userName;
        userAccount=userEntitySession.userAccount;
        enterAccount=userEntitySession.enterAccount;
    }else {
        var transData= {
            userAccount:'',
            userSession:'',
        };
    }
    $.ajax({
        url:"userLoginVerify",
        type:"POST",
        data:transData,
        async:false,
        success:function (data) {
            bakData=JSON.parse(data);
            if(bakData['sessionState']=='success'){
                //session有效
                //$("#saveProject").remove();
                $("#userName").html(userName);
                $("#userDropDown").html(' <li><a href="#"><i class="icon-user"></i> 个人资料</a></li><li class="divider"></li><li><a href="#" onclick="logout()" style="cursor:pointer;"><i class="icon-off"></i>注销</a></li>');
            }else {
                //USER_NAME = data.content;
                /*$(document).ready(function(){
                    tableInit();//初始化表格
                });*/
                //$("#saveProject").remove();
                $("#userName").html(userName);
                $("#userDropDown").html('<li><a href="login.html"><i class="icon-key"></i>登录</a></li><li><a href="userRegister.html" onclick="gotoRegister()"><i class="icon-plus"></i>注册</a></li>');
            }

        },
        error:function (XMLHttpRequest, textStatus, errorThrown) {
            console.log("XMLHttpRequest请求状态码：" + XMLHttpRequest.status);
            console.log("XMLHttpRequest状态码：" + XMLHttpRequest.readyState);
            console.log("textStatus是：" + textStatus);
            console.log("errorThrown是：" + errorThrown);

        }
    })

}

//退出登录函数
function logout() {
    var userJsonStr = sessionStorage.getItem(userSessionName);
    var userEntitySession = JSON.parse(userJsonStr);
    if (userEntitySession!=null){
        var transData= {
            userAccount:userEntitySession.userAccount,
        };
        $.ajax({
            url:"userLogout",
            type:"POST",
            data:transData,
            success:function(data){
                window.location.href='login.html';
                //刷新页面
                //location.reload(true);
            }
        })
    }else {
    }
    sessionStorage.removeItem(userSessionName);
    //sessionStorage.clear();
    window.location.href='login.html';
}

function getUserMenuList() {
    var userJsonStr = sessionStorage.getItem(userSessionName);
    var userEntitySession = JSON.parse(userJsonStr);
    var bakMenuData;
    if (userEntitySession!=null)
    {
        var transData= {
            userAccount:userEntitySession.userAccount,
            userAuth:userEntitySession.userAuth,
        };
        $.ajax({
            url:"userMenu",
            type:"POST",
            data:transData,
            async:false,
            success:function(data){
                //bakMenuData=JSON.parse(data);
                bakMenuData=data;
                if(bakMenuData[0]['status']=='success'){//表明获取数据成功

                //leftContentNavBarAceFyb(titleData, titleiClass, titleHref, cotentData, contentiClass, cotentDataHref);
                }

            }
        })
    }else{
    var transDefaultUserData= {
            userAccount:"default",
            userAuth:"normaluser",
        };
        $.ajax({
            url:"userMenu",
            type:"POST",
            data:transDefaultUserData,
            async:false,
            success:function(data){
                bakMenuData=data;
            }
        })
    }
    return bakMenuData;
}

function getRoleMenuList(roleAuthStr) {
//roleAuthStr:角色字符串
//如果userAccount不为空,那么返回的是userAccount该账号对应的侧边栏目录
//如果userAccount为空,userAuth不为空,那么返回的是userAuth对应的角色字符串的侧边栏目录
    var bakMenuData;
    var transData= {
            userAuth:roleAuthStr,
        };
        $.ajax({
            url:"roleAuthMenu",
            type:"POST",
            data:transData,
            async:false,
            success:function(data){
                //bakMenuData=JSON.parse(data);
                bakMenuData=data;
                if(bakMenuData[0]['status']=='success'){//表明获取数据成功

                //leftContentNavBarAceFyb(titleData, titleiClass, titleHref, cotentData, contentiClass, cotentDataHref);
                }

            }
        })
    return bakMenuData;
}

//验证该用户是否有该网页的权限
function getAuthURL(urlString) {
    var userJsonStr = sessionStorage.getItem(userSessionName);
    var userName='游客';
    var userEntitySession = JSON.parse(userJsonStr);
    var userAccount='';//用户唯一ID,这里是用账号作为唯一的id
    var enterAccount='';//企业唯一ID,这里是用账号作为唯一的id
    bakUrl='#';
    if (userEntitySession!=null){
        var transData= {
            userAccount:userEntitySession.userAccount,
            userSession:userEntitySession.csrftokenfyb,
            userAuth:userEntitySession.userAuth,
            userURL:urlString,
        };
        userName=userEntitySession.userName;
        userAccount=userEntitySession.userAccount;
        enterAccount=userEntitySession.enterAccount;
    }else {
        var transData= {
            userAccount:'',
            userSession:'',
            userAuth:'normaluser',
            userURL:urlString,
        };
    }
    $.ajax({
        url:"getAuthURL",
        type:"POST",
        data:transData,
        async:false,
        success:function (data) {
            bakData=JSON.parse(data);
            if(bakData[0]['status']=='success'){
                bakUrl=bakData[0]['url'];
            }else {
                bakUrl='#';
            }

        },
    })//ajax结束
    return bakUrl;
}

//加载用户信息
    var userAccount='';//用户唯一账号,这里是用账号作为唯一的标识ID
    var enterAccount='';//企业唯一账号,这里是用账号作为唯一的标识ID
    var userJsonStr = sessionStorage.getItem(userSessionName);
    var userEntitySession = JSON.parse(userJsonStr);
    if (userEntitySession!=null){
        userAccount=userEntitySession.userAccount;
        enterAccount=userEntitySession.enterAccount;
    }else {}

//页面自适应
$(document).ready(function () {
    //显示body部分内容
    $(".no-skin").css('display', 'block');
    //获取当前用户登录信息
    getUserInfo();
    $(".showAppNameDiv").html('工业软件');
    var width = $(window).get(0).innerWidth;//获取屏幕高度
    $('#pageContent').css("width", width - 230);//分页长度自适应
});